﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.AndonManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.AndonManagement.IssueTypeVMs
{
    public partial class IssueTypeListVM : BasePagedListVM<IssueType_View, IssueTypeSearcher>
    {
        
        protected override IEnumerable<IGridColumn<IssueType_View>> InitGridHeader()
        {
            return new List<GridColumn<IssueType_View>>{
                
                this.MakeGridHeader(x => x.IssueType_IssueName).SetTitle(@Localizer["Page.问题名称"].Value),
                this.MakeGridHeader(x => x.IssueType_Code).SetTitle(@Localizer["Page.问题编码"].Value),
                this.MakeGridHeader(x => x.IssueType_ActiveColor).SetTitle(@Localizer["Page.激活颜色"].Value),
                this.MakeGridHeader(x => x.IssueType_NormalColor).SetTitle(@Localizer["Page.正常颜色"].Value),
                this.MakeGridHeader(x => x.IssueType_Remark).SetTitle(@Localizer["Page.备用"].Value),
                this.MakeGridHeader(x => x.IssueType_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.IssueType_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.IssueType_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.IssueType_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<IssueType_View> GetSearchQuery()
        {
            var query = DC.Set<IssueType>()
                
                .CheckContain(Searcher.IssueName, x=>x.IssueName)
                .CheckEqual(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.ActiveColor, x=>x.ActiveColor)
                .CheckContain(Searcher.NormalColor, x=>x.NormalColor)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new IssueType_View
                {
				    ID = x.ID,
                    
                    IssueType_IssueName = x.IssueName,
                    IssueType_Code = x.Code,
                    IssueType_ActiveColor = x.ActiveColor,
                    IssueType_NormalColor = x.NormalColor,
                    IssueType_Remark = x.Remark,
                    IssueType_CreateTime = x.CreateTime,
                    IssueType_UpdateTime = x.UpdateTime,
                    IssueType_CreateBy = x.CreateBy,
                    IssueType_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class IssueType_View: IssueType
    {
        
        public string IssueType_IssueName { get; set; }
        public int? IssueType_Code { get; set; }
        public string IssueType_ActiveColor { get; set; }
        public string IssueType_NormalColor { get; set; }
        public string IssueType_Remark { get; set; }
        public DateTime? IssueType_CreateTime { get; set; }
        public DateTime? IssueType_UpdateTime { get; set; }
        public string IssueType_CreateBy { get; set; }
        public string IssueType_UpdateBy { get; set; }

    }

}